package de.graffiti.connection;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class DBConnection
{

	public Object getService(String lookup, Class remoteClass)
	{
		Object tsa = null;
		Properties p = new Properties();
		p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
		p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
		p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
		Context ctx;
		try
		{
			ctx = new InitialContext(p);

			Object ref = ctx.lookup(lookup);

			tsa = PortableRemoteObject.narrow(ref, remoteClass);

		} catch (NamingException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tsa;
	}

}
